Micron Document
`:top
`!SQLJ`! is a working title for efforts to combine `F33f`_`[Java`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(programming_language)]`_`f and `F33f`_`[SQL`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=SQL]`_`f. It was a common effort started around 1997 by engineers from `F33f`_`[IBM`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=IBM]`_`f, `F33f`_`[Oracle`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Oracle_Corporation]`_`f, `F33f`_`[Compaq`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Compaq]`_`f, `F33f`_`[Informix`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Informix_Corporation]`_`f, `F33f`_`[Sybase`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Sybase]`_`f, `F33f`_`[Cloudscape`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Apache_Derby]`_`f and `F33f`_`[Sun Microsystems`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Sun_Microsystems]`_`f.

It consists of the three parts: 0, 1 and 2. Part 0 describes the embedding of SQL statements into Java programs. SQLJ part 0 is the basis for part 10 of the `F33f`_`[SQL:1999`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=SQL:1999]`_`f standard, aka `F33f`_`[SQL Object Language Bindings`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=SQL/OLB]`_`f (SQL/OLB).`:cite-ref-melton2003-1-0[`F5bf`_`[1`#cite-note-melton2003-1]`_`f] SQLJ parts 1 and 2 describes the converse possibility to use Java classes (routines and types) from SQL statements. Parts 1 and 2 are the basis for part 13 of the SQL standard, `F33f`_`[SQL Routines and Types Using the Java Programming Language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=SQL/JRT]`_`f (SQL/JRT).

"SQLJ" is commonly used to refer to just SQLJ part 0, usually when it is contrasted with other means of embedding SQL in Java, like `F33f`_`[JDBC`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JDBC]`_`f.

>>Contents

• `F0af`_`[ANSI and ISO standards`#ansi-and-iso-standards]`_`f
• `F0af`_`[SQLJ part 0`#sqlj-part-0]`_`f
• `F0af`_`[Advantages`#advantages]`_`f
• `F0af`_`[Disadvantages`#disadvantages]`_`f
• `F0af`_`[Examples`#examples]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[References`#references]`_`f
• `F0af`_`[Further reading`#further-reading]`_`f
• `F0af`_`[External links`#external-links]`_`f

-─

>>ANSI and ISO standards

• SQLJ part 0: `F33f`_`[ANSI`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ANSI]`_`f X3.135.10-1998, "Database Language SQL—Part 10: Object Language Bindings (SQL/OLB)"
• SQLJ part 1: ANSI `F33f`_`[NCITS`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=NCITS]`_`f 331.1-1999, "SQLJ—Part 1: SQL Routines Using the Java Programming Language"
• SQLJ part 2: ANSI NCITS 331.2-2000, "SQLJ—Part 2: SQL Types Using the Java Programming Language"

Part 0 was updated for JDBC 2.0 compatibility and ratified by ISO in 2000. The last two parts were combined when submitted to ISO. Part 2 was substantially rewritten for the ISO submission because the ANSI version was not formal enough for a specification, being closer to the style of a `F33f`_`[user manual`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=User_manual]`_`f. The combined version was ratified in 2002.`:cite-ref-melton2003-1-1[`F5bf`_`[1`#cite-note-melton2003-1]`_`f]

• ISO/IEC 9075-10:2000, `*Information technology—Database languages—SQL—Part 10: Object Language Bindings (SQL/OLB)`*
• ISO/IEC 9075-13:2002, `*Information technology—Database languages—SQL—Part 13: SQL Routines and Types Using the Java Programming Language (SQL/JRT)`*.

>>SQLJ part 0

The SQLJ part 0 specification largely originated from Oracle, who also provided the first reference implementation.`:cite-ref-melton2003-1-2[`F5bf`_`[1`#cite-note-melton2003-1]`_`f]

In the following SQLJ is a synonym for SQLJ part 0.

Whereas `F33f`_`[JDBC`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JDBC]`_`f provides an `F33f`_`[API`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Application_programming_interface]`_`f, SQLJ consists of a `F33f`_`[language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Programming_language]`_`f extension. Thus programs containing SQLJ must be run through a `F33f`_`[preprocessor`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Preprocessor]`_`f (the SQLJ translator) before they can be compiled.

>>>Advantages

Some advantages of SQLJ over JDBC include:

• SQLJ commands tend to be shorter than equivalent JDBC programs.
• SQL syntax can be checked at compile time. The returned query results can also be checked strictly.
• Preprocessor might generate static SQL which performs better than dynamic SQL because query plan is created on program compile time, stored in database and reused at runtime. Static SQL can guarantee access plan stability. IBM DB2 supports static SQL use in SQLJ programs.

>>>Disadvantages

• SQLJ requires a preprocessing step.
• Many `F33f`_`[IDEs`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Integrated_Development_Environment]`_`f do not have SQLJ support.
• SQLJ lacks support for most of the common persistence frameworks, such as `F33f`_`[Hibernate`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Hibernate_(Java)]`_`f.
• Oracle 18c (12.2) has desupported SQLJ in the database.

>>>Examples

The following examples compare SQLJ syntax with JDBC usage.

`t
| JDBC | SQLJ |
|---|---|
| PreparedStatement stmt = conn . prepareStatement ( "SELECT LASTNAME" + " , FIRSTNME" + " , SALARY" + " FROM DSN8710.EMP" + " WHERE SALARY BETWEEN ? AND ?" ); stmt . setBigDecimal ( 1 , min ); stmt . setBigDecimal ( 2 , max ); ResultSet rs = stmt . executeQuery (); while ( rs . next ()) { lastname = rs . getString ( 1 ); firstname = rs . getString ( 2 ); salary = rs . getBigDecimal ( 3 ); // Print row... } rs . close (); stmt . close (); | # sql private static iterator EmployeeIterator ( String , String , BigDecimal ); ... EmployeeIterator iter ; # sql [ ctx ] iter = { SELECT LASTNAME , FIRSTNME , SALARY FROM DSN8710 . EMP WHERE SALARY BETWEEN : min AND : max } ; do { # sql { FETCH : iter INTO : lastname , : firstname , : salary } ; // Print row ... } while ( ! iter . endFetch ()); iter . close (); |
`t

`t
| JDBC | SQLJ |
|---|---|
| PreparedStatement stmt = conn . prepareStatement ( "SELECT MAX(SALARY), AVG(SALARY)" + " FROM DSN8710.EMP" ); rs = stmt . executeQuery (); if ( ! rs . next ()) { // Error—no rows found } maxSalary = rs . getBigDecimal ( 1 ); avgSalary = rs . getBigDecimal ( 2 ); if ( rs . next ()) { // Error—more than one row found } rs . close (); stmt . close (); | # sql [ ctx ] { SELECT MAX ( SALARY ), AVG ( SALARY ) INTO : maxSalary , : avgSalary FROM DSN8710 . EMP } ; |
`t

`t
| JDBC | SQLJ |
|---|---|
| stmt = conn . prepareStatement ( "INSERT INTO DSN8710.EMP " + "(EMPNO, FIRSTNME, MIDINIT, LASTNAME, HIREDATE, SALARY) " + "VALUES (?, ?, ?, ?, CURRENT DATE, ?)" ); stmt . setString ( 1 , empno ); stmt . setString ( 2 , firstname ); stmt . setString ( 3 , midinit ); stmt . setString ( 4 , lastname ); stmt . setBigDecimal ( 5 , salary ); stmt . executeUpdate (); stmt . close (); | # sql [ ctx ] { INSERT INTO DSN8710 . EMP ( EMPNO , FIRSTNME , MIDINIT , LASTNAME , HIREDATE , SALARY ) VALUES (: empno , : firstname , : midinit , : lastname , CURRENT DATE , : salary ) } ; |
`t

>>See also

• `F33f`_`[Embedded SQL`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Embedded_SQL]`_`f
• `F33f`_`[Language Integrated Query`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Language_Integrated_Query]`_`f (LINQ)

>>References

`:cite-note-melton2003-1`!1.`! `F0af`_`[↑`#cite-ref-melton2003-1-0]`_`f `:citerefjim-melton2003`aJim Melton (2003). `*Advanced SQL: 1999`*. Morgan Kaufmann. pp. 352-364. `F33f`_`[ISBN`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ISBN_(identifier)]`_`f 978-1-55860-677-7.

>>Further reading

• Connie Tsui, Considering SQLJ for Your DB2 V8 Java Applications, IBM developerworks, 13 Feb 2003
• Owen Cline, Develop your applications using SQLJ, IBM developerworks, 16 Dec 2004
• `:citerefjason-price2001`aJason Price (2001). `*Java Programming With Oracle SQLJ`*. O'Reilly Media. `F33f`_`[ISBN`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ISBN_(identifier)]`_`f 978-0-596-00087-5.

>>External links

• IBM Redbook: DB2 for z/OS and OS/390: Ready for Java
• Oracle SQLJ Developers Guide

`c`F0af`_`[↑ Back to top`#top]`_`f`a